<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c"%>
<%@ page import="java.awt.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%
  String elementId = request.getParameter("elementId");
%>
<html>
<head>
<title>图片信息</title>
<%@ include file="/pages/tm/header.jsp"%>
<script language="JavaScript">
  function chooseImg(filename){
	  if(window.opener.document.getElementById("<%=elementId%>") != null){
	     window.opener.document.getElementById("<%=elementId%>").value = "/pages/images/"+filename;
	     window.close();
	  }
}

</script>
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">
<center><br>
<span class="subject"> <img
	src="<%=request.getContextPath()%>/pages/images/title.gif" alt="图片信息">
图片信息 </span> <br>
<br>
<%
    String appPath = this.getServletContext().getRealPath("");
    String filePath = appPath +"/pages/images";
	System.out.println(filePath);
    java.io.File file = new java.io.File(filePath);
	Set imgRows = new HashSet();
	if (file.isDirectory()) { 
     java.io.File[] files = file.listFiles();
     for(int i=0;i<files.length;i++){
		 File f = files[i];
		 if(f.getName().toLowerCase().endsWith(".gif")){
		   imgRows.add(f.getName());
		 } else if(f.getName().toLowerCase().endsWith(".jpg")){
		   imgRows.add(f.getName());
		 } else if(f.getName().toLowerCase().endsWith(".png")){
		   imgRows.add(f.getName());
		 }
	 }
	}
    System.out.println("size:"+imgRows.size());
	StringBuffer buffer = new StringBuffer();
    buffer.append("<table border=\"0\" cellspacing=1 cellpadding=2 class=\"table-border\">");
    Object[] images = imgRows.toArray();
	int ROW_NUM = 15;
    int rows = (images.length + 1) / ROW_NUM;
    for (int i = 0; i < rows; i++) {
        buffer.append("<tr class=\"table-content\">\n").append("<td align=left width=\"100%\" >");
		for(int j = 0; j < ROW_NUM; j++){
		 int pos = ROW_NUM*i + j;
		 if(pos < imgRows.size()){
          String filename = (String)images[pos];
		  buffer.append("<img src=\"").append(request.getContextPath()).append("/pages/images/").append(filename).append("\"")
		  .append(" alt=\"/pages/images/").append(filename).append("\"")
		  .append(" onclick=\"javascript:chooseImg('").append(filename).append("')\"")
		  .append(" border=\"0\" width=\"16\" height=\"16\" style=\"cursor: hand;\">&nbsp;&nbsp;");
		 }
		}
		buffer.append("</td>\n");      
	}
	buffer.append("</table>");
    out.println(buffer.toString());
%>

</body>
</html>